package com.iafme.service.impl;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.iafme.dto.req.ExamReqDTO;
import com.iafme.dto.res.SubjectResDTO;
import com.iafme.model.Subject;
import com.iafme.mapper.SubjectMapper;
import com.iafme.service.ISubjectService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iafme.utils.ExamSignUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author summer
 * @since 2025/01/05 21:14:43
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class SubjectServiceImpl extends ServiceImpl<SubjectMapper, Subject> implements ISubjectService {



    @Override
    public List<SubjectResDTO> parseSign(String sign) {
        ExamReqDTO examReqDTO = ExamSignUtils.parseSign(sign);
        LambdaQueryWrapper<Subject> eq = Wrappers.lambdaQuery(Subject.class).eq(Subject::getLevelId, examReqDTO.getLevelId())
                .eq(Subject::getProjectId, examReqDTO.getProjectId())
                .eq(Subject::getSessionId, examReqDTO.getShowingsId());
        return Convert.toList(SubjectResDTO.class, this.list(eq));
    }
}
